<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册和登录</title>
</head>
<body>
    
<h1>注册和登录</h1>
<hr >

<form name="frm">
    姓名：<input type="text" name="user" ><br>
    密码：<input type="password" name="pwd"><br />
    <button id="reg" type="button">注册</button>
    <button id="login" type="button">登录</button>
</form>
</body>
<script src="./jquery-3.2.1.min.js"></script>
<script>
    $(function(){
        $('#reg').click(function(){
            $.ajax({
                type: "post",
                url: "http://localhost:8080/user?act=reg",
                data: $("form[name=frm]").serialize(),
                dataType: "json",
                success: function (response) {
                    alert(response.msg);
                }
            });
        });

        $('#login').click(function(){
            $.ajax({
                type: "post",
                url: "http://localhost:8080/user?act=login",
                data: $("form[name=frm]").serialize(),
                dataType: "json",
                success: function (response) {
                    alert(response.msg);
                }
            });
        });
    })
</script>
</html>
